package com.example.denglu.pages.Data;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.denglu.R;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.Random;

public class BarActivity extends AppCompatActivity {

    private ImageView finish;
    private BarChart barchart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bar);
        initView();
        showdata(0,0);
    }

    private void showdata(int boxsum, int grilsum) {
        ArrayList<BarEntry> barEntries = new ArrayList<>();

        int[] February = new int[29];
        int[] june = new int[30];
        for (int i = 0; i < February.length; i++) {
            int i1 = new Random().nextInt(30);
            February[i] = i1;
            barEntries.add(new BarEntry(i, February[i]));
        }
        ArrayList<BarEntry> barEntriess = new ArrayList<>();
        for (int i = 0; i < june.length; i++) {
            int i1 = new Random().nextInt(50);
            june[i] = i1;
            barEntriess.add(new BarEntry(i, june[i]));
        }


        BarDataSet barDataSet = new BarDataSet(barEntries,"2月每小时耗电量");
        barDataSet.setColor(Color.parseColor("#3f48cc"));
        BarDataSet barDataSet1 = new BarDataSet(barEntriess, "六月每小时耗电量");


        BarData barData = new BarData(barDataSet1);
        barData.addDataSet(barDataSet);

        barchart.setData(barData);


        XAxis xAxis = barchart.getXAxis();
        xAxis.setDrawAxisLine(false);
        xAxis.setDrawGridLines(false);
        xAxis.setLabelCount(32,false);
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        barchart.invalidate();
    }

    private void initView() {
        finish = (ImageView) findViewById(R.id.finish);
        barchart = (BarChart) findViewById(R.id.barchart);
    }
}